package com.github.boluo1230.wechat.feign.fallback;

import com.github.boluo1230.wechat.entity.message.WxCustomMsg;
import com.github.boluo1230.wechat.entity.vo.WxResponse;
import com.github.boluo1230.wechat.feign.WxMessageAPI;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MessageFallback implements FallbackFactory<WxMessageAPI> {
    @Override
    public WxMessageAPI create(Throwable cause) {
        log.error("weixin error, msg: " + cause.getMessage(), cause);
        return new WxMessageAPI() {
            @Override
            public WxResponse sendCustomMessage(String accessToken, WxCustomMsg wxCustomMsg) {
                return WxResponse.FAIL;
            }

            @Override
            public WxResponse sendTemplateMessage(String accessToken, WxCustomMsg wxCustomMsg) {
                return WxResponse.FAIL;
            }
        };
    }
}
